%% @author Administrator
%% @doc @todo Add description to account.


-module(account_api).

%% ====================================================================
%% API functions
%% ====================================================================
-export([p_login/1,
		 login/3]).

-include("proto.hrl").
-include("pb_account.hrl").
-include("account.hrl").

%% ====================================================================
%% Internal functions
%% ====================================================================

%% @doc 发送登录请求
p_login(AccountName) ->
	Msg = #c2s_pb_10000{account_name = AccountName},
	player_svr_util:player_send_msg(?PROTO_MSG_LOGIN, Msg).


login(Uid, Roles, Player) ->
	UAccount = #u_account{} = account_ets:data_get(Player),
	NewUAccount = UAccount#u_account{uid = Uid, roles = Roles},
	show_login_info(Roles),
	Player1 = account_ets:data_set(Player, NewUAccount),
	Player1.


show_login_info(Roles) ->
	io:format("==================  Choose Youer Role ======================~n"),
	[begin
		 case lists:keyfind(Index, #role.index, Roles) of
			 #role{level = Level, rid = Rid, role_name = RoleName} ->
			 	io:format("(~p)	RoleName ~p Level ~p Rid ~p~n~n",[Index, RoleName, Level, Rid]);
			 _ ->
				io:format("(~p)	Create Role ~n~n",[Index])
		 end
	 end||Index<-?ROLE_INDEX_LIST].
	


